package com.molichuxing.framework.dto;

import java.io.Serializable;
import java.util.List;

public class Paged<T> implements Serializable {
	private static final long serialVersionUID = 1268006601154824190L;

	/**
	 * 总条数
	 */
	private long total = 0;

	/**
	 * 总页数
	 */
	private int pages = 0;

	/**
	 * 当前页数
	 */
	private int pageNum = 1;

	/**
	 * 每页条数(默认10条)
	 */
	private int pageSize = 10;

	/**
	 * 数据
	 */
	private List<T> list;

	/**
	 * tab标签数据
	 */
	private List<TabDto> tab;

	public Paged() {
	}

	public Paged(long total, int pageSize) {
		this.total = total;
		this.pageSize = pageSize;
		this.pages = (int) (total / pageSize + ((total % pageSize == 0) ? 0 : 1));
	}

	public Paged(List<T> list) {
		this.list = list;
	}

	public Paged(List<T> list, long total, int pageSize) {
		this.list = list;
		this.total = total;
		this.pageSize = pageSize;
		this.pages = (int) (total / pageSize + ((total % pageSize == 0) ? 0 : 1));
	}

	public Paged(List<T> list, List<TabDto> tab, long total, int pageSize) {
		this.list = list;
		this.tab = tab;
		this.total = total;
		this.pageSize = pageSize;
		this.pages = (int) (total / pageSize + ((total % pageSize == 0) ? 0 : 1));
	}

	public int getPages() {
		return pages;
	}

	public Paged<T> setPages(int pages) {
		this.pages = pages;
		return this;
	}

	@Deprecated
	public void setData(List<T> list) {
		this.list = list;
	}

	public List<T> getList() {
		return list;
	}

	public Paged<T> setList(List<T> list) {
		this.list = list;
		return this;
	}

	public List<TabDto> getTab() {
		return tab;
	}

	public Paged<T> setTab(List<TabDto> tab) {
		this.tab = tab;
		return this;
	}

	public long getTotal() {
		return total;
	}

	public Paged<T> setTotal(long total) {
		this.total = total;
		this.pages = (int) (total / this.pageSize + ((total % this.pageSize == 0) ? 0 : 1));
		return this;
	}

	public int getPageNum() {
		return pageNum;
	}

	public Paged<T> setPageNum(int pageNum) {
		this.pageNum = pageNum;
		return this;
	}

	public int getPageSize() {
		return pageSize;
	}

	public Paged<T> setPageSize(int pageSize) {
		this.pageSize = pageSize;
		this.pages = (int) (this.total / pageSize + ((this.total % pageSize == 0) ? 0 : 1));
		return this;
	}

	public boolean isEmpty() {
		if (this.getTotal() == 0 || this.getList() == null || this.getList().isEmpty()) {
			return true;
		}
		return false;
	}
}
